#pragma once

#include <stdio.h>
#include <Windows.h>
#include <vector>
#include <algorithm>
#include <string>

#include "CommonLib/Singleton.h"

class Application : public Singleton<Application>
{
public:
	class SystemElement
	{
	public:
		virtual void init(){}
		virtual void update(double deltaTime){}
		virtual void end(){}
	};
	void addSysElement(SystemElement* pEle){mSysElementList.push_back(pEle);}
	void removeSysElement(SystemElement* pEle)
	{
		SystemElementList::iterator it = std::find(mSysElementList.begin(), mSysElementList.end(), pEle);
		if(it != mSysElementList.end())
			mSysElementList.erase(it);
	}
public:
	Application();
	virtual ~Application();
	
	void loadConfig();
	void init();
	void initScene();
	DWORD run();

public:
	static HINSTANCE ghInstance;
	static HINSTANCE gethInstance(){return ghInstance;}

private:
	void initMainWindow();
	void initSystemElements();

	void doFrame(double deltaTime);
	void doIdleFrame(double deltaTime);	//When application is not actived;

private:
	unsigned mWidth;
	unsigned mHeight;
	bool mbActive;
	std::string mName;

	typedef std::vector<SystemElement*> SystemElementList;
	SystemElementList mSysElementList;
};

